import time
import unittest

from parameterized import parameterized
from selenium.webdriver.support.select import Select
from Finance_fun.page.page07_base_info import PageBaseInfo
from Finance_fun.base.get_driver import GetDriver
from Finance_fun.tool.read_json import read_json


def get_baseinfo_data():
    case = read_json("data07_baseinfo_case.json")
    list_null = []
    for data in case.values():
        list_null.append(
            (
                data["highest_education"],
                data["graduate_school"],
                data["marriage"],
                data["company_industry"],
                data["company_size"],
                data["company_occupation"],
                data["monthly_income_level"],
                data["provice"],
                data["city"],
                data["area"],
             )
        )
    return list_null



class BaseInfoTest(unittest.TestCase):
    def setUp(self):
        self.driver = GetDriver.get_driver()
        self.base_info = PageBaseInfo(self.driver)
        self.base_info.page_click_login_link()
        self.base_info.page_login("13129628532","W123456")

    def tearDown(self):
        GetDriver.quit_driver()

    @parameterized.expand(get_baseinfo_data())
    def test01_my_tz(self,highest_education,graduate_school,marriage,company_industry,company_size,company_occupation,monthly_income_level,provice,city,area):
        # 点击基础信息
        self.base_info.base_info_link()
        # 选择学历
        select= Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[1]/select"))
        select.select_by_visible_text(highest_education)
        # 点击编辑按钮
        self.base_info.click_edit_link()
        # 输入毕业院校
        self.base_info.input_graduate_school(graduate_school)
        # 选择婚姻状况
        select1= Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[3]/select"))
        select1.select_by_visible_text(marriage)
        # 选择公司行业
        select2 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[4]/select"))
        select2.select_by_visible_text(company_industry)
        # 选择公司规模
        select3 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[5]/select"))
        select3.select_by_visible_text(company_size)
        # 选择公司职业
        select4 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[6]/select"))
        select4.select_by_visible_text(company_occupation)
        # 选择月收入水平
        select5 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[7]/select"))
        select5.select_by_visible_text(monthly_income_level)
        # 选择籍贯
        select6 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[8]/select[1]"))
        select6.select_by_visible_text(provice)
        select7 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[8]/select[2]"))
        time.sleep(3)
        select7.select_by_visible_text(city)
        select8 = Select(self.driver.find_element_by_xpath("//*[@id='basic_form']/div[8]/select[3]"))
        time.sleep(3)
        select8.select_by_visible_text(area)